#ifndef QQuickROGenerator_H
#define QQuickROGenerator_H

#include <QObject>
#include <QQmlComponent>

#include "ROSyncCreation.h"

class ROHost;
class RONode;
class RONodePrivate;

class QQuickRONodePrivate;
//RO系统的工厂函数，用于创建QML对象

class ROComponent:public ROSyncCreation
{
    Q_OBJECT
    QML_NAMED_ELEMENT(ROComponent)
    Q_CLASSINFO("DefaultProperty", "comp")
public:
    ROComponent(QObject* parent = nullptr);

    //服务端主动创建一个对象，这会使得所有客户端都创建一个对象
    //players代表该对象的拷贝限制在特定的客户端上,房主Player为无效值，空列表为不限制客户端
    Q_INVOKABLE QObject* spawnObject(const QVariantMap& param = {},const QVariantList& players = {});

    //仅在本端创建一个对象，该对象仅在本端存在
    Q_INVOKABLE QObject* spawnObjectPrivate(const QVariantMap& param = {});

    QQmlComponent *comp() const;
    void setComp(QQmlComponent *newComp);

protected:
    virtual QObject* handleCreation(const QStringList& reason);
signals:
    void compChanged();

private:
    QQmlComponent* m_comp = nullptr;
    friend class QQuickRONode;
    friend class RONodePrivate;
    Q_PROPERTY(QQmlComponent *comp READ comp WRITE setComp NOTIFY compChanged FINAL)
};


#endif
